// import React, { createRef } from "react";
import React, { useRef, useState, useEffect } from "react";

// const App = () => {
//   // 用来获取dom节点
//   const ipt = useRef();

//   const fn = () => {
//     console.log(ipt.current.value);
//   };

//   return (
//     <>
//       <h3>useRef</h3>
//       <input type="text" ref={ipt} />
//       <button onClick={fn}>btn</button>
//     </>
//   );
// };

const App = () => {
  // const [count, set_count] = useState(1);

  // useEffect(() => {
  //   setTimeout(() => {
  //     console.log(count);
  //   }, 2000);
  // }, [count]);

  const count = useRef(1);

  const fn1 = () => {
    // set_count((v) => v - 1);
    count.current = count.current - 1;
    setTimeout(() => {
      console.log(count.current);
    }, 2000);
  };
  const fn2 = () => {
    // set_count((v) => v + 1);
    count.current = count.current + 1;
    setTimeout(() => {
      console.log(count.current);
    }, 2000);
  };
  return (
    <>
      <h3>useRef</h3>
      <p>{count.current}</p>
      <button onClick={fn1}>-</button>
      <button onClick={fn2}>+</button>
    </>
  );
};

export default App;
